<?php
/*
 * ebiz front
 *
 * Customer Model
 *
 * @author li.jf
 *
 */

require_once '../app/core/models/BaseDao.php';
require_once '../app/core/db/DBUtil.class.php';

class WishlistDao extends BaseDao{

    private $tableName = "customer_wishlists";

    public function  __construct($dbUtil) {
        parent::__construct($dbUtil);
    }

    //get my wishlist products
    public function getMyWishlists($customerid){        
$sql = "select cw.id,cw.comment, cw.created,
                pit.attribute_1,pit.value_1,pit.attribute_2,pit.value_2,pit.attribute_3,pit.value_3,pit.attribute_4,pit.value_4,pit.attribute_5,pit.value_5,
                p.title,pit.sale_price,pim.name,pim.folder,p.url_title
                from $this->tableName cw
                left outer join product_items pit on cw.product_item_id=pit.id
                left outer join products p            on p.id =pit.product_id
                left outer join product_images pim on pim.item_id=pit.id
                
where cw.customer_id=1 and cw.is_delete=0 and cw.product_item_id = pit.id and pim.item_id=pit.id and pit.product_id = p.id order by cw.created desc";
        $param=array($customerid);
        return $this->dbUtil->SelectData($sql, $param);
    }

    //add productitem  into mywishlist
    public function addNewWishlist($param){         
        $sql="insert into $this->tableName (customer_id,product_item_id,comment,modified,created) values(?,?,?,now(),now())";
        return $this->dbUtil->ExecuteQuery($sql, $param);
    }

    //remove info from mywishlist
    public function removeWishlist($param){         
        $sql = "update $this->tableName set is_delete=1 where id=? and customer_id=?";
        return $this->dbUtil->ExecuteQuery($sql, $param);
    }

    //upadate mywishlist info
    public function updateWishlist($param){   
        $sql  ="update $this->tableName set comment=? where id=? and customer_id=? and is_delete=0";
        return $this->dbUtil->ExecuteQuery($sql, $param);
    }
}